<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>门店管理</title>
    <#include "/common/link.ftl">

</head>
<body class="hold-transition skin-black sidebar-mini">
<div class="wrapper">
    <#include "/common/navbar.ftl">
    <!--菜单回显-->
    <#assign currentMenu="business"/>
    <#include "/common/menu.ftl">
    <div class="content-wrapper">
        <section class="content-header">
            <h1>门店编辑</h1>
        </section>
        <section class="content">
            <div class="box">
                <form class="box-body" style="margin: 10px" class="form-horizontal" id="editForm" action="/business/saveOrUpdate" enctype="multipart/form-data" method="post" >
                    <input type="hidden" name="id" value="${business.id}">
                    <div class="row">
                        <div class="col-md-5">
                            <div class="form-group">
                                <label>门店名称：</label>
                                <input type="text" class="form-control" name="name" value="${business.name}"
                                       placeholder="请输入门店名称">
                            </div>
                            <div class="form-group">
                                <label >门店电话：</label>
                                <input type="text" class="form-control" name="tel" value="${business.tel}"
                                       placeholder="请输入门店电话">
                            </div>
                        </div>
                        <div class="col-md-5">
                            <div class="form-group">
                                <label>门店地址：</label>
                                <input type="text" class="form-control" name="address" value="${business.address}"
                                       placeholder="请输入门店地址">
                            </div>
                            <div class="form-group">
                                <label>经营日期：</label>
                                <input type="text" class="form-control input-date"  value="${(business.openDate?string('yyyy-MM-dd'))!}"
                                       name="openDate"
                                       placeholder="请输入经营日期"/>
                            </div>
                        </div>
                    </div>
                    <div class="row">
                        <div class="form-group col-md-10">
                            <label>门店介绍：</label>
                            <textarea class="form-control" rows="4"   name="intro"
                                      placeholder="请输入门店介绍">${business.intro}</textarea>
                        </div>
                    </div>
					 <div class="row">
                        <div class="form-group col-md-10">
                            <label>经营范围：</label>
                            <textarea class="form-control" rows="4"  name="scope"
                                      placeholder="请输入经营范围"
                                      name="scope">${business.scope}</textarea>
                        </div>
                    </div>
                    <div class="row">
                        <div class="col-md-5">
                            <div class="form-group">
                                <label>法人姓名：</label>
                                <input type="text" class="form-control" name="legalName" value="${business.legalName}" placeholder="请输入法人姓名">
                            </div>
                            <div class="form-group">
                                <label>法人电话：</label>
                                <input type="text" class="form-control" name="legalTel" value="${business.legalTel}" placeholder="请输入法人电话">
                            </div>
                            <div class="form-group">
                                <label>上传营业执照：</label>

                                <#if business.licenseImg??>
                                   <a class="btn" target="_blank" href="${business.licenseImg}">
                                    <i class="fa fa-user"></i> 查看附件
                                  </a>
                                </#if>
                                <#-- 携带原本的图片地址路径(解决图片路径丢失问题)-->
                                <input type="hidden" name="licenseImg" value="${business.licenseImg}"/>
                                <#-- 上传文件的时候才使用 -->
                                <input type="file" class="form-control" name="file" >
                            </div>
                        </div>
                        <div class="col-md-5">
                            <div class="form-group">
                                <label>法人身份证：</label>
                                <input type="text" class="form-control"  name="legalIdcard" value="${business.legalIdcard}"
                                       placeholder="请输入法人身份证">
                            </div>
                            <div class="form-group">
                                <label>营业执照号码：</label>
                                <input type="text" class="form-control"  name="licenseNumber" value="${business.licenseNumber}"
                                       placeholder="请输入营业执照号码">
                            </div>
                            <div class="form-group">
                                <label >门店性质：</label>
                                <select class="form-control" name="mainStore">
                                    <option value="0">分店</option>
                                    <option value="1">总店</option>
                                </select>
                                <script>
                                    $("select[name=mainStore]").val(${(business.mainStore?string("1","0"))!})
                                </script>
                            </div>
                        </div>

                    </div>
                    <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                    <button type="submit" class="btn btn-primary btn-submit">保存</button>
                </form>

            </div>
        </section>
    </div>
    <#include "/common/footer.ftl">
</div>

<script>
    //要提交ajax怎么选择
    //1.看有没有表单, 如果没有表单 用 $.get $.post $.ajax
    //2.有表单用jquery-form插件
    //3. 看按钮 button按钮 (点击事件,ajaxSubmit)
    //3. 看按钮 submit按钮 (页面加载完毕,ajaxForm)

    //ajaxForm 会把表单升级为ajax , 不会做提交的操作
    //ajaxSubmit  会把表单升级为ajax , 并且马上做提交的操作

    $("#editForm").ajaxForm(function (data) {
        if(data.success){
            Swal.fire({
                title: '操作成功',
                icon: 'success'
            }).then(() => {
                window.location.href = "/business/list";
            })
        }else{
            Swal.fire(
                '操作失败',
                data.msg,
                'error'
            )
        }
    })



   /* $(".btn-submit").click(function () {
        //jquery-form
        //直接利用form中的属性进行提交
        $("#editForm").ajaxSubmit(function (data) {
            if(data.success){
                Swal.fire({
                    title: '操作成功',
                    icon: 'success'
                }).then(() => {
                    window.location.href = "/business/list";
                })
            }else{
                Swal.fire(
                    '操作失败',
                    data.msg,
                    'error'
                )
            }
        })
    })*/
</script>

</body>
</html>
